/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import Model.Airplane;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author Sony
 */
public class AirplaneHelper {

    Session session;

    public AirplaneHelper() {
        this.session = HibernateUtil.getSessionFactory().getCurrentSession();
    }
    
    public List<Airplane> getAllAirplane() {
        List<Airplane> lstAirplane = null;
        try {
            org.hibernate.Transaction tx = this.session.beginTransaction();
            Query q = this.session.createQuery("from Airplane");
            lstAirplane = (List<Airplane>)q.list();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return lstAirplane;
    }
    
    public void updateAirplane(Airplane a){
        try {
            org.hibernate.Transaction tx = this.session.beginTransaction();
            this.session.save(a);
            tx.commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public void deleteAirplane(Airplane a){
         try {
            org.hibernate.Transaction tx = this.session.beginTransaction();
            this.session.delete(a);
            tx.commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
